package interceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

public class SecurityInterceptor extends HandlerInterceptorAdapter {

	private String[] allowUrls;

	public void setAllowUrls(String[] allowUrls) {
		this.allowUrls = allowUrls;
	}

	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
		String requestURL = request.getRequestURI().replace(request.getContextPath(), "");
		if (null != allowUrls && allowUrls.length > 0) {
			for (String allowUrl : allowUrls) {
				if (requestURL.contains(allowUrl)) {
					return true;
				}
			}
		}
		return true;
	}

}
